var BaseController = new require("./basecontroller");
var userRoles = require("../initial_load/user_roles");
var mailer = require("../utilities/mailer");

function Controller(){
	BaseController.call(this);
}

Controller.prototype = Object.create (BaseController.prototype);
Controller.prototype.DEFAULT_VALUE = 0;
Controller.prototype.FORM_ENTRIES = Array(
		"has_manager_role", "has_admin_role", "has_cashier_role",
		"can_view_backend", //"can_add_backend","can_edit_backend","can_delete_backend",
		"can_view_user", "can_add_user", "can_edit_user", "can_delete_user",
		"can_view_user_group", "can_add_user_group", "can_edit_user_group", "can_delete_user_group",
		"can_view_user_permission", "can_add_user_permission", "can_edit_user_permission", "can_delete_user_permission",
		"can_view_company", "can_add_company", "can_edit_company", "can_delete_company",
		"can_view_payment", "can_add_payment", "can_edit_payment", "can_delete_payment",
		"can_view_module", "can_add_module", "can_edit_module", "can_delete_module",
		"can_view_won_auction", "can_add_won_auction", "can_edit_won_auction", "can_delete_won_auction",
		"can_view_order_payment", "can_add_order_payment", "can_edit_order_payment", "can_delete_order_payment",
		"can_view_branch", "can_add_branch", "can_edit_branch", "can_delete_branch",
		"can_view_settings", "can_add_settings", "can_edit_settings", "can_delete_settings");

Controller.prototype.SEARCH_ENTRIES = Array("name", "date_added", "user_group.name");
Controller.prototype.TABLE = "user_group_permission"; //table for this controller
Controller.prototype.CONTROLLER = "user-permission"; //controllername
Controller.prototype.PAGE = "user_permission";
Controller.prototype.FORM_VIEW = "backend/user-permission/user-permission-form";
Controller.prototype.LIST_VIEW = "backend/user-permission/user-permission-list";

Controller.prototype.RECORDS_PER_PAGE = 20;

Controller.prototype.LIST_JOIN_TABLES = 
{"user_group_id" : //field
	{ 							
		table : "user_group",//table
	    joinType : "left",
		fieldToJoin : "id",//default is id
		fields: Array('id','name')//fields to retrieve
	}
}; 

Controller.prototype.FORM_JOIN_TABLES = Controller.prototype.LIST_JOIN_TABLES;


Controller.prototype.postUpdate = function(req, res, data){
    userRoles.loadAccessRights();
   // mailer.sendEmail("buncasanaldrin@gmail.com");
	return data;
}

//for reference data
Controller.prototype.REFERENCE_DATA_LIST = {
		0 : {name : "permissionsData", query : "select label,controller,description from module where archived = 1 ", appendWhereClause: false},
}


module.exports = new Controller();

/*
ADDITIONAL CODES
override methods
*/
/*UserController.prototype.preInsert = function(req, res, data){
	return data;
}*/